﻿<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Content_search extends Front_Controller {
 	var $siteSetings;
	var $announcement;
	var $lineclass; 
	var $des_tags;		//目的地标签   
	var $carclass;
	function __construct()
	{
		parent::__construct();
		$this->load->helper(array('form'));
		$this->load->model('front/Frontget_ml');
		$this->load->model('front/Search_m');
	//	$this->output->enable_profiler(true);
		$this->siteSetings=$this->Frontget_ml->get_site_settings();	//获取站点设置
		$this->announcement=$this->Frontget_ml->get_announcement();	//获取网站公告
		$this->lineclass=$this->Frontget_ml->get_lineclass();//获取线路分类
		$this->carclass=$this->Frontget_ml->get_carclass();//获取汽车分类
		$this->newsclass=$this->Frontget_ml->get_newsclass();//获取汽车分类
		$this->des_tags=$this->Search_m->get_des_tags();	//获取网站公告
		
	//	$this->load->library('form_validation');	
	//	$this->form_validation->set_rules('cateID');
		//$this->form_validation->set_rules('purposeUrl', 'purposeUrl','required');
	}

	public function search($search_case=0){	//搜索线路
			$cateid=$this->uri->segment(3);	//线路分类ID
			$tagid=$this->uri->segment(4);	//线路tag ID	
		if((int)$search_case or (int)$tagid){
			$friend_links=$this->Frontget_ml->get_friend_links();//获取友情链接
			//分页
			$this->load->library('pagination');
			$config['base_url'] = site_url('/content_search/search/'.$cateid.'/'.$tagid.'/');
			
			$total_rows= $this->Search_m->get_search_list($cateid,$tagid,1);//获取查询条件下的记录总数
			$config['total_rows'] =$total_rows[0]->icount;
			//		print_r($config['total_rows']);
			$config['per_page'] = 10;
			$config['uri_segment'] = 5;
			$config['full_tag_open'] = '';
			$config['full_tag_close'] = '';
			$config['cur_tag_open']= '&nbsp;<span class="current">';
			$config['cur_tag_close']= '</span>';	
			$config['prev_link']= '上一页';
			$config['next_link']= '下一页';	
			$config['first_link']= ' 首页';
			$config['last_link']= ' 尾页';
			//	$config['use_page_numbers'] = TRUE;
			$this->pagination->initialize($config);
			$begin_record=$this->uri->segment(5);
			//分页end		
			$search_list=$this->Search_m->get_search_list($cateid,$tagid,0,$begin_record,$config['per_page']);//获取线路列表
			$current_title="搜索条件：";
				if(!empty($this->lineclass['classname'][$this->uri->segment(3)])){$current_title.=$this->lineclass['classname'][$this->uri->segment(3)]."--";}
				if(!empty($this->des_tags['tags_name'][$this->uri->segment(4)])){	$current_title.=$this->des_tags['tags_name'][$this->uri->segment(4)];}

			$data=array("current_title"=>$current_title,"friend_links"=>$friend_links,"newsclass"=>$this->newsclass,"carclass"=>$this->carclass,"siteSetings"=>$this->siteSetings,"lineclass"=>$this->lineclass,"announcement"=>$this->announcement,"des_tags"=>$this->des_tags,"search_list"=>$search_list);			
			
			$this->load->view('inc/header',$data);
			$this->load->view('searchpage_v');
		}else{
			redirect(base_url());	//参数错误
		}			
	}
	public function tags_ajax($cid=0)	//返回对应类型的tas数据
	{
		if((int)$cid){
			$tags_pid=$this->Search_m->get_tags_pid($cid);	//通过classid查询tags的id
			$tags=$this->des_tags;
			if($tags_pid && $tags){
				$xml="<?xml version='1.0' encoding='utf-8' standalone='yes'?>";
					$xml.="<rows>";
						if(!empty($tags['parentid'][$tags_pid])):
							foreach($tags['parentid'][$tags_pid] as $key=>$value){
						//		$xml.="<row  id='".$tags_pid."' pid='0' name='".$tags['tags_name'][$tags_pid]."' />";
							//		$xml.="<row  id='".$key."' pid='".$tags_pid."' name='".$tags['tags_name'][$key]."' />";
								$xml.="<row  id='".$key."' pid='0' name='".$tags['tags_name'][$key]."' />";
									if(!empty($tags['parentid'][$key])):
										foreach($tags['parentid'][$key] as $subkey=>$subvalue){
											$xml.="<row  id='".$subkey."' pid='".$key."' name='".$tags['tags_name'][$subkey]."' />";
										}
									endif;
							}
						endif;
					$xml.="</rows>";						
				echo($xml) ;			
			
			}
		}
	}
}
/* 搜索线路
$this->form_validation->set_rules('plantime');
		$this->form_validation->set_rules('lineclass');
		$this->form_validation->set_rules('trav_day');
		$this->form_validation->set_rules('price_around');
		$argument_price_around=0;
		if ($this->form_validation->run() == FALSE && $search_case!="searchpage"){
			echo "failure".$search_case; //$search_case!="searchpage" //判断是否是搜索分页
		}else{
			//参数验证
			if($this->form_validation->run() == true ){
				if(strtotime(set_value('plantime'))){
					$plantime=strtotime(set_value('plantime'));
				}else{$plantime=0;
				}
				if((int)set_value('lineclass')){
					$cateid=(int)set_value('lineclass');
				}else{$cateid=0;
				}
				if((int)set_value('trav_day')){
					$trav_day=(int)set_value('trav_day');
				}else{$trav_day=0;
				}
	
				if((string)set_value('price_around')){
					$price_around=(string)set_value('price_around');
					$argument_price_around=(string)set_value('price_around');
					$price_around=explode("-",$price_around);
					if(count($price_around)==2){
						if(!preg_match("/^\d*$/",(int)$price_around[0]) || !preg_match("/^\d*$/",(int)$price_around[1]) ){
							$price_around=0;
							$argument_price_around=0;
						}
					}else{
						$price_around=0;
						$argument_price_around=0;
					}
					print_r($argument_price_around);
				}
				else{$price_around=0;
				}
			}else{
				$cateid=$this->uri->segment(4);
				$plantime=$this->uri->segment(5);
				$trav_day=$this->uri->segment(6);
				$price_around=$this->uri->segment(7);
				if(preg_match("/^\d*$/",(int)$cateid)){
					$cateid=0;
				}
				if(strtotime($plantime)){
					$plantime=0;
				}
				if(preg_match("/^\d*$/",(int)$trav_day)){
					$trav_day=0;
				}
				if((string)$price_around){
					$price_around=(string)$price_around;
					$argument_price_around=(string)$price_around;
					$price_around=explode("-",$price_around);
					if(count($price_around)==2){
						if(!preg_match("/^\d*$/",(int)$price_around[0]) || !preg_match("/^\d*$/",(int)$price_around[1]) ){
							$price_around=0;
							$argument_price_around=0;
						}
					}else{
						$price_around=0;
						$argument_price_around=0;
					}
					//				print_r($argument_price_around);
				}
				else{$price_around=0;
				}
			}
			//参数验证end
			//	echo $plantime."<br>".$cateid."<br>".$trav_day."<br>".$price_around."<br>";
			//-----------------------------------------------------------------------------
			$left_lines=$this->Frontget_ml->get_left_lines();//获取左侧热门线路
			$friend_links=$this->Frontget_ml->get_friend_links();//获取友情链接
			//按条件搜素
			//分页
			$this->load->library('pagination');
			$config['base_url'] = site_url('main/content_search/searchpage/'.$cateid.'/'.$plantime.'/'.$trav_day.'/'.$argument_price_around.'/');
	
			$total_rows= $this->Frontget_ml->get_search_list($cateid,$plantime,$trav_day,$price_around,0,0,1);//获取查询条件下的记录总数
			$config['total_rows'] =$total_rows[0]->icount;
			//		print_r($config['total_rows']);
			$config['per_page'] = 5;
			$config['uri_segment'] = 8;
			$config['full_tag_open'] = '<p>';
			$config['full_tag_close'] = '</p>';
			//	$config['use_page_numbers'] = TRUE;
			$this->pagination->initialize($config);
			$begin_record=$this->uri->segment(8);
			$get_search_list=$this->Frontget_ml->get_search_list($cateid,$plantime,$trav_day,$price_around,$begin_record,$config['per_page']);//获取线路列表
			//分页end
			//	$get_search_list=$this->Frontget_ml->get_search_list($cateid,$plantime,$trav_day,$price_around);//获取线路列表
			//按条件搜素end
			$data=array("siteSetings"=>$this->siteSetings,"lineclass"=>$this->lineclass,"get_search_list"=>$get_search_list,"announcement"=>$this->announcement,"left_lines"=>$left_lines,"friend_links"=>$friend_links);
			$this->load->view('inc/header',$data);
			$this->load->view('searchpage');
				
		}
 */